/*
 * Review 评测
 */

import Review from 'constants/review';
import { CALL_BOOK_API } from '../middlewares';

export function createLevel(data: Record<string, any>) {
  return {
    data,
    [CALL_BOOK_API]: {
      types: [Review.CREATE_LEVEL, Review.CREATE_LEVEL_SUCCESS, Review.CREATE_LEVEL_FAIL],
      uri: '/study-api/a/levels',
      method: 'POST',
      body: data,
    },
  };
}

export function updateLevel(levelId: number, data: Record<string, any>) {
  return {
    data,
    [CALL_BOOK_API]: {
      types: [Review.UPDATE_LEVEL, Review.UPDATE_LEVEL_SUCCESS, Review.UPDATE_LEVEL_FAIL],
      uri: `/study-api/a/levels/${levelId}`,
      method: 'PUT',
      body: data,
    },
  };
}

export function removeLevel(levelId: number) {
  return {
    levelId,
    [CALL_BOOK_API]: {
      types: [Review.REMOVE_LEVEL, Review.REMOVE_LEVEL_SUCCESS, Review.REMOVE_LEVEL_FAIL],
      uri: `/study-api/a/levels/${levelId}`,
      method: 'DELETE',
    },
  };
}

export function fetchLevelList(filters: Record<string, any> = { page: 1, pageSize: 99 }) {
  return {
    filters,
    [CALL_BOOK_API]: {
      types: [
        Review.FETCH_LEVEL_LIST,
        Review.FETCH_LEVEL_LIST_SUCCESS,
        Review.FETCH_LEVEL_LIST_FAIL,
      ],
      uri: '/study-api/a/levels',
      method: 'GET',
      body: filters,
    },
  };
}

export function createWord(data: Record<string, any>) {
  return {
    data,
    [CALL_BOOK_API]: {
      types: [Review.CREATE_WORD, Review.CREATE_WORD_SUCCESS, Review.CREATE_WORD_FAIL],
      uri: '/study-api/a/level-words',
      method: 'POST',
      body: data,
    },
  };
}

export function updateWord(levelId: number, data: Record<string, any>) {
  return {
    data,
    [CALL_BOOK_API]: {
      types: [Review.UPDATE_WORD, Review.UPDATE_WORD_SUCCESS, Review.UPDATE_WORD_FAIL],
      uri: `/study-api/a/level-words/${levelId}`,
      method: 'PUT',
      body: data,
    },
  };
}

export function removeWord(wordId: number) {
  return {
    wordId,
    [CALL_BOOK_API]: {
      types: [Review.REMOVE_WORD, Review.REMOVE_WORD_SUCCESS, Review.REMOVE_WORD_FAIL],
      uri: `/study-api/a/level-words/${wordId}`,
      method: 'DELETE',
    },
  };
}

export function fetchWordList(filters: Record<string, any>) {
  return {
    filters,
    [CALL_BOOK_API]: {
      types: [Review.FETCH_WORD_LIST, Review.FETCH_WORD_LIST_SUCCESS, Review.FETCH_WORD_LIST_FAIL],
      uri: '/study-api/a/level-words',
      method: 'GET',
      body: filters,
    },
  };
}

export function createTest(data: Record<string, any>) {
  return {
    data,
    [CALL_BOOK_API]: {
      types: [Review.CREATE_TEST, Review.CREATE_TEST_SUCCESS, Review.CREATE_TEST_FAIL],
      uri: `/study-api/a/tests`,
      method: 'POST',
      body: data,
    },
  };
}

/**
 * 修改试题内容
 */
export function updateTest(testId: number, data: Record<string, any>) {
  return {
    testId,
    [CALL_BOOK_API]: {
      types: [Review.UPDATE_TEST, Review.UPDATE_TEST_SUCCESS, Review.UPDATE_TEST_FAIL],
      uri: `/study-api/a/tests/${testId}`,
      method: 'PUT',
      body: data,
    },
  };
}

/**
 * 删除试题及相关数据
 * @param testId: 试题ID
 */
export function removeTest(testId: number) {
  return {
    testId,
    [CALL_BOOK_API]: {
      types: [Review.REMOVE_TEST, Review.REMOVE_TEST_SUCCESS, Review.REMOVE_TEST_FAIL],
      uri: `/study-api/a/tests/${testId}`,
      method: 'DELETE',
    },
  };
}

/**
 * 查询试题详情
 * @param data TestModal
 */
export function fetchTestDetail(testId: number) {
  return {
    testId,
    [CALL_BOOK_API]: {
      types: [Review.FETCH_TEST, Review.FETCH_TEST_SUCCESS, Review.FETCH_TEST_FAIL],
      uri: `/study-api/a/tests/${testId}`,
      method: 'GET',
    },
  };
}

/**
 * 查询评测试题列表
 */
export function fetchTestList(filters: Record<string, any>) {
  return {
    filters,
    [CALL_BOOK_API]: {
      types: [Review.FETCH_TEST_LIST, Review.FETCH_TEST_LIST_SUCCESS, Review.FETCH_TEST_LIST_FAIL],
      uri: `/study-api/a/tests`,
      method: 'GET',
      body: filters,
    },
  };
}

export function fetchTestTplList(filters: Record<string, any>) {
  return {
    filters,
    [CALL_BOOK_API]: {
      types: [
        Review.FETCH_TEST_TPL_LIST,
        Review.FETCH_TEST_TPL_LIST_SUCCESS,
        Review.FETCH_TEST_TPL_LIST_FAIL,
      ],
      uri: `/study-api/a/tests`,
      method: 'GET',
      body: filters,
    },
  };
}
